﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;
/// <summary>
/// Summary description for _Payment_type
/// </summary>
public class _Payment_type
{
	public _Payment_type()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public int _id { get; set; }
    public string _type_name { get; set; }

    static SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);

    public static List<_Payment_type> SelectPaymentTypes()
    {
        _Payment_type item = new _Payment_type();
        List<_Payment_type> list = new List<_Payment_type>();
        SqlCommand SelCmd = new SqlCommand("SELECT * FROM PAYMENT_TYPE", conn);
        try
        {
            conn.Open();
            SqlDataReader dr = SelCmd.ExecuteReader();
            while (dr.Read())
            {
                item._id = (int) dr[0];
                item._type_name = dr[1].ToString();
                list.Add(item);
            }
            dr.Close();
            conn.Close();
        }
        catch { System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Error in reading data!')</SCRIPT>"); }
        return list;
    }

    public static _Payment_type SelectPayType(string id)
    {
        _Payment_type PayType = new _Payment_type();
        SqlCommand SelCmd = new SqlCommand("SELECT * FROM payment_type WHERE id=@id", conn);
        SelCmd.Parameters.Add(new SqlParameter("@id", System.Data.SqlDbType.Int)).Value = id;
        try
        {
            conn.Open();
            SqlDataReader dr = SelCmd.ExecuteReader();
            while (dr.Read())
            {
                PayType._id = (int) dr[0];
                PayType._type_name = dr[1].ToString();
            }
            dr.Close();
            conn.Close();
        }
        catch { System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Error in reading data!')</SCRIPT>"); }
        return PayType;
    }
}